<?php
require RELATIVE_ROOT.'Classes/smarty/Smarty.class.php';
/**
 * XiteCode template object
 *
 * The template object extends Smarty
 *
 * @copyright (c) 2006 A.Sleep <a.sleep@asleep.net> under the GNU GPL version 2
 * @author A.Sleep <a.sleep@asleep.net>
 * @package core
 * @access public
 * @see http://smarty.php.net/
 */

class Template extends Smarty {

  /**
   * @var string
   * @access public
   */
  /**
   * Holds the path to the default template directory
   */
  public $template_dir;
  /**
   * Holds the path to the compiled template directory
   * This directory will be made (if possible) if it does not exist.
   */
  public $compile_dir;
  /**
   * False if caching is off.
   * @var bool
   */
  public $caching;

  function __construct()
  {
    global $Session;
    $this->Smarty();
    $this->template_dir = RELATIVE_ROOT.'Templates/Default';
    $this->caching      = false;

    array_push($this->plugins_dir, RELATIVE_ROOT.'Includes/TemplatePlugins/');

    $cDir = '/tmp/ctemplates';

    if (!is_dir($cDir)) {
      if (!mkdir($cDir)) {
	echo '<h1>The compile directory for the template system could not be created.<br />Please create the directory '.$cDir.' and chown to the user &amp; group running the web server application.</h1>';
	exit;
      }
    }

    $this->compile_dir  = '/tmp/ctemplates';

    $this->assign(array('LINK_ROOT' => LINK_ROOT,
			'errors'    => $Session->errors,
			'messages'  => $Session->messages,
			'cfg'       => $GLOBALS['cfg']
			));

    unset($Session->errors);
    unset($Session->messages);
    return;
  }


  /**
   * Displays our templates
   *
   * @param string $template Template filename
   * @param bool $display If false rendered template will be returned as a string
   * @return mixed
   */

  public function render($template, $display = true)
  {
    if ($display) {
      parent::display($template);
      return;
    }
    return parent::fetch($template);
  }

}

?>
